class Mind::DojosController < Mind::MindController
  # GET /dojos
  # GET /dojos.xml
  def index
    @dojos = Dojo.find(:all, :conditions => "doer_id = #{current_friend.id}")

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @dojos }
    end
  end

  # GET /dojos/1
  # GET /dojos/1.xml
  def show
    @dojo = Dojo.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @dojo }
    end
  end

  # GET /dojos/new
  # GET /dojos/new.xml
  def new
    @dojo = Dojo.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @dojo }
    end
  end

  # GET /dojos/1/edit
  def edit
    @dojo = Dojo.find(params[:id])
  end

  # POST /dojos
  # POST /dojos.xml
  def create
    @dojo = Dojo.new(params[:dojo])
    @dojo.doer = current_friend
    
    respond_to do |format|
      if @dojo.save
        flash[:notice] = 'Dojo was successfully created.'
        format.html { redirect_to(mind_dojos_url) }
        format.xml  { render :xml => @dojo, :status => :created, :location => @dojo }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @dojo.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /dojos/1
  # PUT /dojos/1.xml
  def update
    @dojo = Dojo.find(params[:id])

    respond_to do |format|
      if @dojo.update_attributes(params[:dojo])
        flash[:notice] = 'Dojo was successfully updated.'
        format.html { redirect_to(mind_dojos_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @dojo.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /dojos/1
  # DELETE /dojos/1.xml
  def destroy
    @dojo = Dojo.find(params[:id])
    @dojo.destroy #if @dojo.doer.id == current_friend.id

    respond_to do |format|
      format.html { redirect_to(mind_dojos_url) }
      format.xml  { head :ok }
    end
  end
end
